<template>
  <div class="person">
    <h2>一辆{{ car.brand }}，价值{{ car.price }}</h2>
    <button @click="changePrice">修改汽车的价格</button>
    <ul>
      <li v-for="(item, index) in games" :key="index">{{ item.name }}</li>
    </ul>
    <button @click="changeGame">修改游戏的名字</button>
    <hr>
    <h2>测试：{{ obj.a.b.c }}</h2>
        <button @click="changeObj">修改游戏的名字</button>
  </div>
</template>
<script lang="ts" setup name="Person234">
  // ref  ===> 可以定义：基本类型、对象类型的响应式数据 RefImpl
  // reactive ===> 只能定义：对象类型的响应式数据 Proxy(Object)
  import {ref, reactive} from 'vue'
  // 被reactive包裹后就变成了响应式对象
  let car = reactive({ brand: '奔驰', price: 100})
  let games = reactive([
    { id: '111', name: '王者荣耀'},
    { id: '222', name: '原神'},
    { id: '333', name: '三国志'}
  ])
  let obj = reactive({
    a: {
      b:{
        c: 666
      }
    }
  })
  console.log(car)
  function changePrice(){
    car.price += 10
    console.log(car)
  }

  function changeGame(){
    games[0].name = '绝地求生'
  }

  function changeObj(){
    obj.a.b.c = 999
  }

</script>

<style scoped>
    .person {
        background-color: #ddd;
        box-shadow: 0 0 10px;
        border-radius: 10px;
        padding: 20px;
    }
    button {
        margin: 0 5px;
    }
</style>
